//
//  ClassifyButton.m
//  SDSY
//
//  Created by 蓝布鲁 on 2017/3/20.
//  Copyright © 2017年 蓝布鲁. All rights reserved.
//

#import "ClassifyButton.h"

@implementation ClassifyButton

#pragma mark - 自定义初始化方法
- (instancetype)initWithFrame:(CGRect)frame title:(NSString *)title image:(UIImage *)image {
    if (self = [super initWithFrame:frame]) {
        // 设置Btn标题
        [self setTitle:title forState:UIControlStateNormal];
        
        // 设置title颜色
        [self setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        
        // 设置title文字大小
        self.titleLabel.font = [UIFont systemFontOfSize:12];
        
        // 设置Btn icon
        [self setImage:image forState:UIControlStateNormal];
        
    }
    return self;
}

#pragma mark - 系统回调方法
- (void)layoutSubviews {
    [super layoutSubviews];
    // 1.调整image位置
    CGRect imageFrame = self.imageView.frame;
    imageFrame.origin.x = (self.frame.size.width - imageFrame.size.width) * 0.5;
    imageFrame.origin.y = 5;
    self.imageView.frame = imageFrame;
    
    // 2.调整title位置
    [self.titleLabel sizeToFit];
    CGRect titleFrame = self.titleLabel.frame;
    titleFrame.origin.x = (self.frame.size.width - titleFrame.size.width) * 0.5;
    titleFrame.origin.y = self.imageView.bottomY + 5;
    self.titleLabel.frame = titleFrame;
}

@end
